'use strict';

const Controller = require('egg').Controller;

class UserController extends Controller {
    async success(data, message) {
        // affectedRows 编辑 更新 删除
        // 获取  get select
        if (data.affectedRows !== undefined) {
            // 操作结果
            if (data.affectedRows >= 1) {
                this.ctx.body = {
                    success: true,
                    message: "操作成功"
                }
            } else {
                this.ctx.body = {
                    success: false,
                    message: "操作失败"
                }
            }
        } else {
            // 返回数据
            this.ctx.body = {
                success: true,
                data
            }
        }
    }
    async error(message = '请求失败') {
        this.ctx.body = {
            success: false,
            message
        }
    }
}

module.exports = UserController;
